package org.ruoyi.interview.controller;

import java.util.List;

import org.ruoyi.common.satoken.utils.LoginHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ruoyi.common.web.core.BaseController;
import org.ruoyi.common.core.domain.R;
import org.ruoyi.common.mybatis.core.page.TableDataInfo;
import org.ruoyi.common.mybatis.core.page.PageQuery;
import org.ruoyi.common.log.annotation.Log;
import org.ruoyi.common.log.enums.BusinessType;
import org.ruoyi.interview.domain.InterviewConversation;
import org.ruoyi.interview.service.IInterviewConversationService;

/**
 * 对话记录Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/interview/conversation")
public class InterviewConversationController extends BaseController {

    @Autowired
    private IInterviewConversationService interviewConversationService;

    /**
     * 查询对话记录列表
     */
    @GetMapping("/list")
    public TableDataInfo<InterviewConversation> list(InterviewConversation interviewConversation, PageQuery pageQuery) {
        interviewConversation.setUserId(LoginHelper.getUserId());
        return interviewConversationService.selectInterviewConversationList(interviewConversation, pageQuery);
    }

    /**
     * 获取对话记录详细信息
     */
    @GetMapping(value = "/{conversationId}")
    public R<InterviewConversation> getInfo(@PathVariable("conversationId") Long conversationId) {
        return R.ok(interviewConversationService.selectInterviewConversationById(conversationId));
    }

    /**
     * 新增对话记录
     */
    @Log(title = "对话记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@RequestBody InterviewConversation interviewConversation) {
        interviewConversation.setUserId(LoginHelper.getUserId());
        return toAjax(interviewConversationService.insertInterviewConversation(interviewConversation));
    }

    /**
     * 修改对话记录
     */
    @Log(title = "对话记录", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody InterviewConversation interviewConversation) {
        interviewConversation.setUserId(LoginHelper.getUserId());
        return toAjax(interviewConversationService.updateInterviewConversation(interviewConversation));
    }

    /**
     * 删除对话记录
     */
    @Log(title = "对话记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{conversationIds}")
    public R<Void> remove(@PathVariable Long[] conversationIds) {
        return toAjax(interviewConversationService.deleteInterviewConversationByIds(conversationIds));
    }
}
